package com.boot.service;

import com.boot.entity.Menu;
import com.boot.entity.User;
import com.boot.mapper.MenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuService {

    @Autowired
    MenuMapper menuMapper;

    public List<Menu> list(){
        return menuMapper.list();
    }

    public List<Menu> list(Integer current,Integer pageSize){
        Integer start = (current - 1) * pageSize;
        return menuMapper.listPages(start,pageSize);
    }

    public Integer pages(Integer current, Integer pageSize) {
        int count = menuMapper.count();
        return count % pageSize == 0 ? count / pageSize : count / pageSize + 1 ;
    }

    public void deleteAll(List<Long> ids) {
        menuMapper.deleteAll(ids);
    }

    public void delById(Long id) {
        menuMapper.delById(id);
    }

    public Menu getById(Long id) {
        return menuMapper.getById(id);
    }

    public void saveOrUpdate(Menu menu) {
        if(menu.getId()!=null){
            menuMapper.updateById(menu);
        }else{
            menuMapper.save(menu);
        }
    }
}
